/*
 * Created: 2022-08-25 20:07:36
 * Author : 涛涛涛
 */

import React, { FC, useContext } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import { ProductItemContext } from '@/pages/Home/ProductList/ProductItem/ProductItemContext';

export interface IProps extends ICompProps {}
InProgressOrSellUp.defaultProps = {} as Partial<IProps>;
function InProgressOrSellUp(props: IProps) {
    const { className, style } = props;
    const { status } = useContext(ProductItemContext);
    const localClassName = useClassName('InProgressOrSellUp', className, {
        [status]: status,
    });
    return (
        <RootView className={localClassName} style={style}>
            <Text className="InProgressOrSellUp-status">
                {status === 'dropping' && '进行中'}
                {status === 'soldOut' && '已售罄'}
            </Text>
        </RootView>
    );
}
export default React.memo(InProgressOrSellUp as FC<IProps>);

const RootView = styled(View)`
    &.InProgressOrSellUp {
        padding: 10px 15px;
        width: fit-content;
        border-radius: 8px;
        font-size: 24px;
        color: #fff;
        line-height: 1;
        &.dropping {
            background-color: rgba(0, 0, 0, 0.6);
        }
        &.soldOut {
            background-color: rgba(245, 245, 245, 0.6);
        }
    }
`;
